//类装饰器
/*
function fun1( target:any ){
    target.prototype.userName = '张三';
    target.age = 19;
}
@fun1
class Person1{
}
let p1 = new Person1();
//@ts-ignore
console.log( p1.userName );
//@ts-ignore
console.log( Person1.age );
*/

//装饰器工厂
/*
function fun2( options:any ){
    return function( target:any ){
        target.prototype.userName = options.name;
        target.prototype.userAge = options.age;
    }
}
@fun2({
    name:'张三',
    age:18
})
class Person2{

}

let p2 = new Person2();
//@ts-ignore
console.log( p2.userName ,p2.userAge );
*/

//装饰器组合
/*
function demo1( target:any ){
    console.log('demo1');
}
function demo2(){
    console.log('demo2');
    return function(target:any){
        console.log('demo2 内部');
    }
}
function demo3(){
    console.log('demo3');
    return function(target:any){
        console.log('demo3 内部');
    }
}
function demo4( target:any ){
    console.log('demo4');
}

@demo1
@demo2()
@demo3()
@demo4
class Person3{

}
let p3 = new Person3();
*/

//属性装饰器
/*
function fun4( options:any ){
    return function(target:any , attr:any){
        target[attr] = options;
    }
}
class Person4{
    //@ts-ignore
    @fun4('李四')
    //@ts-ignore
    userName:string;
}

let p4 = new Person4();
console.log( p4.userName );
*/

function test( target: any, propertyKey: string, descriptor: PropertyDescriptor ) {
    console.log( target );
    console.log( propertyKey );
}

class Person {
    @test
    sayName() {
        console.log( 'say name...' )
    }
}

let p = new Person();
p.sayName()
